package protocol.transactions;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;
import protocol.meta.HeadRecommend;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.netease.http.THttpRequest;

public class TransactionHeadRecommend extends XoneBaseTransaction {

    public TransactionHeadRecommend() {
        super(TRANSACTION_TYPE_HEAD_RECOMMEND);
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if (obj instanceof JsonElement) {
            HeadRecommend[] headRecommends = null;
            JsonElement list = ((JsonElement)obj).getAsJsonObject().get("list");
            Gson gson = new Gson();
            headRecommends = gson.fromJson(list, HeadRecommend[].class);
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, headRecommends);
        }
    }

    @Override
    public void onTransact() {
        THttpRequest request = XoneProtocol.getInstance().createHeadRecommendRequest();
        sendRequest(request);
    }
}
